import { uniqueId } from 'lodash'
import main from './modules/main'
import market from './modules/market'
import measure from './modules/measure'
import licence from './modules/licence'
import oa from './modules/oa'
import base from './modules/base'
import sys from './modules/sys'

/**
 * @description 给菜单数据补充上 path 字段
 * @description https://github.com/d2-projects/d2-admin/issues/209
 * @param {Array} menu 原始的菜单数据
 */
function supplementPath (menu) {
  return menu.map(e => ({
    ...e,
    path: e.path || uniqueId('d2-menu-empty-'),
    ...e.children ? {
      children: supplementPath(e.children)
    } : {}
  }))
}

export const menuHeader = supplementPath([
  {
    path: '/main',
    title: '首页',
    icon: 'home'
  },
  {
    path: '/market',
    title: '市场管理',
    icon: 'flag'
  },
  {
    path: '/measure/search',
    title: '计量业务',
    icon: 'shopping-cart'
  },
  {
    path: '/licence',
    title: '证书记录',
    icon: 'file'
  },
  {
    path: '/finance',
    title: '财务管理',
    icon: 'jpy'
  },
  {
    path: '/oa',
    title: 'OA系统',
    icon: 'sitemap'
  },
  {
    path: '/base',
    title: '基础数据',
    icon: 'database'
  },
  {
    path: '/sys',
    title: '系统设置',
    icon: 'wrench'
  }
])

export const menuAside = supplementPath([
  main,
  market,
  measure,
  licence,
  oa,
  base,
  sys
])
